<template>
  <a-card :bordered="false">
    <s-table
      size="default"
      ref="table"
      rowKey="indicesName"
      :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
      :columns="columns"
      :data="loadData"
      :showPagination="false"
    >
      <span slot="index" slot-scope="text, record, index"> {{ index + 1 }} </span>
      <span slot="action" slot-scope="text, record">
        <a v-if="editEnabel" @click="handleEdit(record)">编辑</a>
      </span>
    </s-table>
    <field-weight-modal ref="modal" @ok="handleOk" />
  </a-card>
</template>

<script>
import { STable } from '@/components'
import { fieldWeightList } from '@/api/system'
import FieldWeightModal from '@/views/system/components/FieldWeightModal'
export default {
  name: 'FieldWeight',
  components: {
    STable,
    FieldWeightModal
  },
  data () {
    return {
      description: '',
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      queryParam: {},
      typeOptions: [],
      selectedRowKeys: [],
      selectedRows: [],
      editEnabel: this.$auth('ElasticSearch.FieldWeightManager.FieldWeightEdit'),
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'index' }
        },
        {
          title: '字段',
          dataIndex: 'field'
        },
        {
          title: '权重',
          dataIndex: 'weight'
        },
        {
          title: '更新时间',
          dataIndex: 'updateTime'
        },
        {
          title: '更新人',
          dataIndex: 'updateUser'
        },
        {
          title: '操作',
          width: '200px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return fieldWeightList(Object.assign(parameter, {}))
      }
    }
  },
  created () {
  },
  methods: {
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    },
    handleOk () {
      this.$refs.table.refresh(true)
    },
    handleEdit (record) {
      this.$refs.modal.edit(record)
    }
  },
  watch: {
  }
}
</script>
